<!DOCTYPE html>
<html lang="en" ng-app="app">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/angular-1.3.0.js"></script>
</head>
<body>
    <div ng-controller="myCtrl">
        <button ng-click="btn_click('morning')">button1</button>
        <button ng-click="btn_click2('afternoon')">button2</button>
    </div>
    <script type="application/javascript">
        var app = angular.module("app",[]);
        // factory定义服务
        app.config(function ($provide) {
            $provide.factory("myService1",["$window",function ($window) {
                return{
                    say : function (t) {
                        $window.alert(t);
                    }
                }
            }]);
        });
        // service定义服务
        app.config(function ($provide) {
            $provide.service("myService2",["$window",function ($window) {
                return{
                    say : function (t) {
                        $window.console.log(t);
                    }
                }
            }]);
        });
        app.controller("myCtrl",["$scope","myService1","myService2",function ($scope,myService1,myService2) {
            $scope.btn_click = function (t) {
                myService1.say(t);
            };
            $scope.btn_click2 = function (t) {
              myService2.say(t);
            };
        }]);
    </script>
</body>
</html>